/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import { isArray } from 'lodash';
import { message } from 'antd';
import type { ResponseReturned } from '@/utils/request';

/** 微快递会员 会员列表 */
export async function getList(params: WkdVipMange.ListSearchParams) {
  return request<WkdVipMange.ListResponse>('/wkd/MemberCard/lists', {
    method: 'POST',
    data: params,
  }).then(({ code, data = [], msg }) => {
    if (code == 0 || code == 1009) {
      if (isArray(data) && data.length > 0) {
        return {
          total: data.length,
          success: true,
          data: data,
          current: 1,
        };
      }
    } else {
      message.error(msg);
    }
    return {};
  });
}
/** 微快递会员 操作记录列表 */
export async function getRecordList(params: WkdVipMange.RecordSearchParams) {
  return request<WkdVipMange.RecordListResponse>('/wkd/MemberCard/openMemberCardRecord', {
    method: 'POST',
    data: params,
  }).then(({ code, data, msg }) => {
    if (code == 0 || code == 1009) {
      const list = data?.data;
      if (isArray(list) && list.length > 0) {
        return {
          total: data.total,
          success: true,
          data: list,
          current: 1,
        };
      }
    } else {
      message.error(msg);
    }
    return {};
  });
}
/** 微快递会员 开通会员 */
export async function openVip(params: { card_id: string; user_id: string; channel: string }) {
  return request<ResponseReturned>('/wkd/MemberCard/openMemberCard', {
    method: 'POST',
    data: params,
  });
}
/** 微快递会员 退款信息 */
export async function getRefundInfo(params: { user_id: string; page: number; channel: string }) {
  return request<WkdVipMange.RefundListResponse>('/wkd/MemberCard/refundOpenMemberCardRecord', {
    method: 'POST',
    data: params,
  });
}
/** 微快递会员 会员卡信息 */
export async function getCardInfo(params: { user_id: string }) {
  return request<WkdVipMange.CardListResponse>('/wkd/MemberCard/getConfigList', {
    method: 'POST',
    data: params,
  });
}
